package com.situ.gym.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.situ.gym.pojo.entity.Reserve;
import com.situ.gym.service.IReserveService;
import com.situ.gym.util.Result;
import com.situ.gym.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Gao
 * @since 2025-05-08
 */
@RestController
@RequestMapping("/reserve")
public class ReserveController {
    @Autowired
    private IReserveService reserveService;

    @GetMapping("/selectByUserId")
    public Result selectByUserId() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");

        QueryWrapper<Reserve> wrapper = new QueryWrapper<>();
        wrapper.select("course_id");
        wrapper.eq("user_id", id);
        List<Reserve> list = reserveService.list(wrapper);
        List<Long> courseIdList = list.stream().map(reserve -> reserve.getCourseId()).collect(Collectors.toList());
        return Result.ok(courseIdList);
    }
}

